import allure
import pytest
from page.app_page_login import PageLogin
from script import log


class TestAppLogin:

    @allure.tag("登录模块")
    @allure.description("账号密码都正确")
    @allure.title("app登录成功")
    @allure.severity(allure.severity_level.BLOCKER)
    @pytest.mark.flaky(reruns=2, reruns_delay=1)
    @pytest.mark.smoke
    def test01_login_success(self, driver):
        # 创建登录对象
        self.app_login = PageLogin(driver)
        # 调用登录方法
        self.app_login.page_login('18683060002', 'abc123')
        # 打印结果
        result = self.app_login.get_toast_result()
        print(f"登录结果：{result}")
        log.info(f"登录结果：{result}")
        # 断言结果
        assert "登录成功" == result
        # 截图
        self.app_login.app_shot("login_success")

    @allure.tag("登录模块")
    @allure.description("账号正确,密码错误")
    @allure.title("app登录失败")
    @allure.severity(allure.severity_level.CRITICAL)
    def test02_login_fail_pwd_error(self, driver):
        # 创建登录对象
        self.app_login = PageLogin(driver)
        # 调用登录方法
        self.app_login.page_login('13800000001', '123')
        # 打印结果
        result = self.app_login.get_toast_result()
        print(result)
        log.info(f"登录结果：{result}")
        # 断言结果
        assert "密码错误!" == result
        # 截图
        self.app_login.app_shot("login_fail_pwd_error")

    # 当前用例版本号
    Version = 1.0

    @pytest.mark.skipif(Version == 1.0, reason="条件成立，跳过执行")
    def test03_login_fail_username_exist(self, driver):
        # 创建登录对象
        self.app_login = PageLogin(driver)
        # 调用登录方法
        self.app_login.page_login('13812340002', '123456')
        # 打印结果
        result = self.app_login.get_toast_result()
        print(result)
        log.info(f"登录结果：{result}")
        # 断言结果
        assert "账号不存在!" == result
        # 截图
        self.app_login.app_shot("login_fail_username_exist")

    @pytest.mark.skip(reason="该用例未实现，直接跳过")
    def test04_login_fail_username_error(self, driver):
        pass


